package com.base.app_core.View.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.base.app_core.R;
import com.base.app_core.R2;
import com.base.app_core.base.impl.BaseAdapter;
import com.base.app_core.base.impl.BaseViewHolder;
import com.base.app_core.model.Region;
import com.base.app_core.util.XYBAUtils;

import java.util.List;

import butterknife.BindView;

/**
 * Created by xiangheng.song on 2017/3/10.
 */

public class RegionAdapter extends BaseAdapter<Region, RegionAdapter.ViewHolder> {

    private Long selectedId;

    public RegionAdapter(Context context, List<Region> list) {
        super(context, list);
    }

    @Override
    protected void fillData(Region item, RegionAdapter.ViewHolder holder) {
        holder.text.setText(item.getName());
        if(item.getId().equals(selectedId)){
            holder.text.setTextColor(XYBAUtils.getColor(R.color.red));
            holder.icon.setVisibility(View.VISIBLE);
        }else{
            holder.text.setTextColor(XYBAUtils.getColor(R.color.black));
            holder.icon.setVisibility(View.GONE);
        }
    }

    public void setSelectedId(Long selectedId) {
        this.selectedId = selectedId;
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.region_item;
    }

    public class ViewHolder extends BaseViewHolder {

        @BindView(R2.id.text)
        TextView text;

        @BindView(R2.id.icon)
        ImageView icon;

        public ViewHolder(View view) {
            super(view);
        }
    }
}
